﻿using GreenXi.ViewModel;
using Quartz;
using System.Threading.Tasks;

namespace GreenXi.Job
{
    internal class BackupJob : IJob
    {
        public static ITrigger GetTrigger()
        {
            var backupIntervalDay = GlobalVariables.BackupIntervalDay;
            var backupIntervalTime = GlobalVariables.BackupIntervalTime;
            string cronStr = Util.Converter.GetCornString(backupIntervalDay, backupIntervalTime);

            return TriggerBuilder
                .Create()
                .WithCronSchedule(cronStr)
                .Build();
        }

        public Task Execute(IJobExecutionContext context)
        {
            BackupInfoViewModel backupInfoViewModel = new();
            backupInfoViewModel.BackupDirect(null, null);
            return Task.CompletedTask;
        }
    }
}
